#!/bin/bash

# 桌面美化一键脚本
# 功能：安装现代化桌面美化组件、Firefox浏览器和中文语言包

# 检查是否为root用户
if [ "$(id -u)" -ne 0 ]; then
    echo "请使用root用户或通过sudo运行此脚本"
    exit 1
fi

# 检测发行版
if [ -f /etc/os-release ]; then
    . /etc/os-release
    OS=$ID
    OS_LIKE=$ID_LIKE
    VERSION=$VERSION_ID
else
    echo "无法检测Linux发行版"
    exit 1
fi

# 安装依赖和美化组件
echo "正在安装依赖和美化组件..."

case $OS in
    ubuntu|debian|pop|linuxmint)
        apt update
        apt install -y git curl wget gnome-tweaks gnome-shell-extensions \
                       dconf-editor fonts-noto-cjk fonts-noto fonts-roboto \
                       firefox firefox-locale-zh-hans
        ;;
    fedora|centos|rhel)
        dnf install -y git curl wget gnome-tweaks dconf-editor \
                      google-noto-cjk-fonts google-noto-fonts-common \
                      firefox firefox-locale-zh-CN
        ;;
    arch|manjaro)
        pacman -Sy --noconfirm git curl wget gnome-tweaks dconf-editor \
                              noto-fonts noto-fonts-cjk firefox firefox-i18n-zh-cn
        ;;
    *)
        echo "不支持的发行版: $OS"
        exit 1
        ;;
esac

# 安装第三方主题和图标
echo "正在安装第三方主题和图标..."
mkdir -p /tmp/desktop-beautify
cd /tmp/desktop-beautify

# 安装WhiteSur主题 (macOS风格)
git clone https://github.com/vinceliuice/WhiteSur-gtk-theme.git
cd WhiteSur-gtk-theme
./install.sh -t all -l -i arch
./tweaks.sh -f
cd ..

# 安装McMojave图标
git clone https://github.com/vinceliuice/McMojave-circle.git
cd McMojave-circle
./install.sh
cd ..

# 安装Plymouth主题 (启动画面)
if [ "$OS" = "ubuntu" ] || [ "$OS" = "debian" ]; then
    apt install -y plymouth plymouth-themes
    git clone https://github.com/adi1090x/plymouth-themes.git
    cd plymouth-themes
    chmod +x install.sh
    ./install.sh
    update-initramfs -u
    cd ..
fi

# 配置Firefox中文界面
echo "配置Firefox中文界面..."
case $OS in
    ubuntu|debian|pop|linuxmint)
        update-locale LANG=zh_CN.UTF-8
        ;;
    fedora|centos|rhel)
        localectl set-locale LANG=zh_CN.UTF-8
        ;;
    arch|manjaro)
        sed -i 's/#zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/' /etc/locale.gen
        locale-gen
        ;;
esac

# 安装扩展管理器
echo "安装扩展管理器..."
case $OS in
    ubuntu|debian|pop|linuxmint)
        apt install -y chrome-gnome-shell
        ;;
    fedora)
        dnf install -y chrome-gnome-shell
        ;;
    arch|manjaro)
        pacman -Sy --noconfirm chrome-gnome-shell
        ;;
esac

# 推荐用户安装的GNOME扩展
echo "推荐安装以下GNOME扩展来增强体验:"
echo "1. User Themes - 允许使用第三方主题"
echo "2. Dash to Panel - 现代化任务栏"
echo "3. Arc Menu - 应用程序菜单"
echo "4. Clipboard Indicator - 剪贴板历史"
echo "5. OpenWeather - 天气插件"
echo ""
echo "可以通过浏览器访问 https://extensions.gnome.org 安装这些扩展"

# 清理临时文件
cd ~
rm -rf /tmp/desktop-beautify

echo ""
echo "桌面美化完成!"
echo "请重启系统以应用所有更改"
echo "重启后可以使用Gnome Tweaks工具进一步自定义外观"